//
//  ContentView.swift
//  iFishApp
//
//  Created by Bob on 2022/3/4.
//

import SwiftUI

struct ContentView: View {
    @StateObject var customTabbarVM: CustomTabbarViewModel = CustomTabbarViewModel()
        @State var currentTab: CustomTabBar = .home
        
        var body: some View {
            GeometryReader { proxy in
                ZStack(alignment: .bottom) {
                    TabView(selection: $currentTab) {
                        HomeView()
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                            .tag(CustomTabBar.home)
                            .environmentObject(customTabbarVM)
                        
                        NicePlayView()
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                            .tag(CustomTabBar.niceplay)
                        
                        MessageView()
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                            .tag(CustomTabBar.message)
                        
                        MineView()
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                            .tag(CustomTabBar.mine)
                    }
                    CustomTabBarView(safeAreaEdgeInsets: proxy.safeAreaInsets, currentTab: $currentTab)
                        .opacity(customTabbarVM.atFront ? 1 : 0)
                    
                }
                .ignoresSafeArea(.all, edges: .bottom)
            }
        }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
